from sympy import symbols, limit, sin, exp, log

def composite_limit_example():
    x = symbols('x')
    
    # 内层函数：g(x) = x²，当x→0时，g(x)→0
    g = x**2
    
    # 外层函数：f(u) = sin(u)/u，当u→0时，f(u)→1
    u = symbols('u')
    f = sin(u)/u
    
    # 复合函数：f(g(x)) = sin(x²)/x²
    composite_func = sin(x**2)/(x**2)
    
    # 计算极限
    lim_g = limit(g, x, 0)  # 内层函数极限
    lim_f = limit(f, u, 0)  # 外层函数极限
    lim_composite = limit(composite_func, x, 0)  # 复合函数极限
    
    print("复合函数极限正例分析:")
    print(f"内层函数g(x) = {g}")
    print(f"lim(x→0)g(x) = {lim_g}")
    print(f"外层函数f(u) = {f}")
    print(f"lim(u→0)f(u) = {lim_f}")
    print(f"复合函数f(g(x)) = {composite_func}")
    print(f"lim(x→0)f(g(x)) = {lim_composite}")
    print(f"定理验证: {lim_composite} = {lim_f}")
    
    # 检查条件是否满足
    print("\n条件验证:")
    print("1. lim(x→0)g(x) = 0 存在 ✓")
    print("2. lim(u→0)f(u) = 1 存在 ✓")
    print("3. 当x≠0时，g(x)=x²≠0（满足g(x)≠u₀条件） ✓")
    
    return composite_func, lim_composite

composite_func, lim_composite = composite_limit_example()